<%@ page language="java" isELIgnored="false" import="java.util.*"
	pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="com.testingedu.common.QueryResult"%>
<%@page import="com.testingedu.model.TCategory"%>
<%QueryResult queryResult  = (QueryResult)request.getAttribute("queryResult");%>

<!-- roleAdd.jsp -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/pingTai/pingTai.css">
		<script src="${pageContext.request.contextPath}/js/utils.js" type="text/javascript" language="javascript"></script>
		<SCRIPT type="text/javascript" language="javascript" src="${pageContext.request.contextPath}/js/jquery-1.7.2.js"></SCRIPT>
		<script charset="utf-8" src="${pageContext.request.contextPath}/editor/kindeditor.js"></script>
		<script charset="utf-8" src="${pageContext.request.contextPath}/editor/lang/zh_CN.js"></script>
	<script>
		var editor;
		KindEditor.ready(function(K) {
			editor = K.create('textarea[name="content"]', {
				cssPath : '${pageContext.request.contextPath}/editor/plugins/code/prettify.css',
				uploadJson : '${pageContext.request.contextPath}/admin/editor/upload',
				fileManagerJson : '${pageContext.request.contextPath}/admin/editor/manager',
				allowFileManager : true
			});
			prettyPrint();
		});
	</script>
	</head>
	<body>
		<table width="100%" border="0" align="center" cellpadding="0"
			cellspacing="0">
			<tr>
				<td height="3"></td>
			</tr>
			<tr height="20" valign="baseline">
				<td bgcolor="#353c44">
					<img src="${pageContext.request.contextPath}/images/pingTai/tb.gif"
						width="14" height="14" />
					<span class="STYLE1">添加信息</span>
				</td>
				<td align="right" bgcolor="#353c44">
					<span class="STYLE1"> </span>
				</td>
			</tr>
			<tr>
				<td height="3" colspan="2"></td>
			</tr>
		</table>
		<form id="_form">
			<table width="100%" border="0" cellpadding="0" cellspacing="1"
				bgcolor="#a8c7ce">
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" colspan="1">
						标题:
					</td>
					<td align="left">
						<input type="text" name="title" id="_title" size="80">
					</td>
					<td align="right">
						置顶:
					</td>
					<td align="left">
						<input type="checkbox" name="top">
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="5%">
						级别:
					</td>
					<td width="30%">
						<select name="level">
							<option value="1" selected="selected">一般重要</option>
							<option value="2">重要</option>
							<option value="3">很重要</option>
						</select>
					</td>
					<td align="right" width="25%">
						类型:
					</td>
					<td width="50%">
						<select name="categoryId">
							<%for(Object o : queryResult.getResultList()) {
								TCategory c = (TCategory) o;%>
							<option value="<%=c.getId() %>"><%=c.getName() %></option>
							<%}%>
						</select>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="center" width="100%" colspan="4">
						<table>
							<tr bgcolor="#FFFFFF" class="STYLE19">
								<td width="15%" align="right">
									内容:
								</td>
								<td>
									<textarea id="editor_id" name="content"
										style="width: 800px; height: 400px;">
									</textarea>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19" bordercolor="white">
					<td colspan="4" align="center">
						好的关键字可以让别人更容易找到此篇信息（可选）
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">

					<td align="center" width="30%" colspan="4">
						关键字:
					
						<input type="text" name="keywords" id="namesId" size=60>
						多个关键字用半角逗号隔开，最多3个
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td colspan="4" align="center">
						<input type="button" class="button2" value="添加" onclick="save_to_trainInfo();"/>
						<input type="reset" class="button2" value="重置" />
						<input type="button" class="button2" value="预览"
							onclick="javascript:doSubmit('toaddTbTrainInfo');" />
						<input type="button" class="button2" value="返回"
							onclick="javascript:history.go(-1);" />
					</td>
				</tr>
			</table>
		</form>
	</body>
	<script type="text/javascript">
function save_to_trainInfo() {
	var title = $('#_title').val();
	if(!utils_stringLength(title, '标题', 1, 100))
		return;
	var description = $('#editor_id').val();
	if(description.length == 0) {
		alert('新闻类容不能为空');
		return;
	}
	editor.sync();
	$.ajax({
	   	type: "POST",
	   	url: "${pageContext.request.contextPath}/admin/trainInfo/add",
	   	data: $('#_form').serialize(),
	   	dataType: "json",
	   	success: function(json){
     		if(json.msg != 'null')
     			alert(json.msg);
     		else {
     			if(json.id > 0) {
     				window.location.href="${pageContext.request.contextPath}/admin/trainInfo/list";
     			}
     		}
   		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
   					alert("操作时发生了错误，请重试");
				},
		});
}
	</script>
</html>
